package com.qinghuan.Test;

import com.qinghuan.pojo.Category;
import com.qinghuan.pojo.Product;
import com.qinghuan.service.ProductService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * @Auther: qinghuan
 * @Date: 2022/3/5 21:39
 * @Description:
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:application.xml")
public class TestSpring {

    @Autowired
    Category category;
    @Autowired
    Product product;
    @Autowired
    ProductService productService;

    public static void main(String[] args) {
        ApplicationContext context = new
                ClassPathXmlApplicationContext(
                new String[]{"application.xml"});

        Category category = (Category) context.getBean("c");

        System.out.println(category.getName());

        Product product = (Product) context.getBean("p");

        System.out.println(product.getName());
        System.out.println(product.getCategory().getName());

        ProductService service = (ProductService) context.getBean("s");
        service.doSomeService();

    }

    @Test
    public void test() {
        System.out.println(category.getName());
    }

    @Test
    public void test1() {
        System.out.println(product.getCategory().getName());
        productService.doSomeService();
    }

}
